<?php

use think\migration\Migrator;
use think\migration\db\Column;

class File extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $userModel = $this->table('file');
        $userModel->addColumn('name', 'string', ['limit'=>255])
        ->addColumn('url', 'text', [])
        ->addColumn('path', 'string', ['limit'=>255])
        ->addColumn('hash', 'string', ['limit'=>128])
        ->addColumn('user_id', 'integer', ['signed' => false, 'default'=>0,'comment'=>'用户id'])
        ->addColumn('create_time', 'datetime')
        ->addColumn('update_time', 'datetime')
        ->addColumn('status', 'integer', ['default'=>1,'comment'=>'状态 0待上传 1已上传 2已失效 3已删除']);
        $userModel->create();

        $routesModel = $this->table('routes');
        $routes = [
            ['pid' => 1, 'name' => '文件管理', 'redirect' => '',
                'componentStr' => 'list/list.vue',                   'path' => '/file',            'meta' => '{"affix": false, "title": "文件管理", "elIcon": "Files", "hidden": false, "svgIcon": "", "activeMenu": "/config", "alwaysShow": false, "breadcrumb": true}',
                'create_time' => date('Y-m-d H:i:s'), 'update_time' => date('Y-m-d H:i:s'), 'status' => 1],
        ];
        $routesModel->insert($routes)->saveData();
    }
}
